<?php // This pages allow users to delete uploaded files

 if (isset($_GET['f_id'])) {
	$f_id = (int) $_GET['f_id'];
} else {
	$f_id = 0;
}

if ($f_id > 0) {
	require('db.php');
	
	$query = "SELECT upload_id,file_name, file_type, file_size FROM uploads WHERE upload_id=$f_id";
	$result = mysql_query($query);
	list($up_id,$fn, $ft, $fs) = mysql_fetch_array($result, MYSQL_NUM);
	$fn = iconv('UTF-8', 'GBK', $fn);
	if (unlink("./uploads/$up_id-$fn")){
		$query="DELETE FROM uploads WHERE upload_id=$up_id";
		$result=mysql_query($query);
		mysql_close();
		header("Location:view_files.php");
	} else {
	    echo "<script>alert('File could not be moved.');</script>";	
	}
} else {
	$page_title='File Delete';
	echo '<p><font color="red">Please select a valid file to delete.</font></p>';
	
}

?>

